home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / conqsrc.lha / Conquest / src / taskforce.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-03  |  4.6 KB  |  223 lines

  1. /* Taskforce.c: Routines for taskforces */
  2.  
  3. #include <stdio.h>
  4. #include "defs.h"
  5. #include "structs.h"
  6. #include "vars.h"
  7. #include "protos.h"
  8.  
  9. void make_tf()
  10. {
  11.   int tf_num, new_tf; 
  12.  
  13.   printf("ew tf- from tf:");
  14.   tf_num = get_char()-'A'+1;
  15.   clear_left();
  16.  
  17.   if ((tf_num<1) || (tf_num>26) || (tf[player][tf_num].eta!=0) || 
  18.       (tf[player][tf_num].dest==0))
  19.   {
  20.     error("  !illegal tf");
  21.     return;
  22.   }
  23.  
  24.   if (tf[player][tf_num].blasting) 
  25.   {
  26.     error(" !Tf is blasting a planet     ");
  27.     return;
  28.   }
  29.  
  30.   point(1,19);
  31.   new_tf = split_tf(tf_num);
  32.   point(1,20);
  33.   print_tf(new_tf);
  34.   point(1,21);
  35.   print_tf(tf_num);
  36. }
  37.  
  38. int split_tf(int tf_num)
  39. {
  40.   int new_tf;
  41.   char ships; 
  42.   int x,y,n_ships;
  43.   char iline[81];
  44.  
  45.   new_tf = get_tf(player,tf[player][tf_num].dest);
  46.   tf_stars[tf[player][tf_num].dest][player]++;
  47.  
  48.   printf(" ships:");
  49.   point(8,y_cursor);
  50.  
  51.   get_line(iline);
  52.   ships = get_token(iline,&n_ships);
  53.  
  54.   if (ships==' ') /* Split entire fleet */
  55.   {
  56.     tf[player][new_tf].s=tf[player][tf_num].s;
  57.     tf[player][new_tf].t=tf[player][tf_num].t;
  58.     tf[player][new_tf].c=tf[player][tf_num].c;
  59.     tf[player][new_tf].b=tf[player][tf_num].b;
  60.     tf[player][tf_num].s=0;
  61.     tf[player][tf_num].t=0;
  62.     tf[player][tf_num].c=0;
  63.     tf[player][tf_num].b=0;
  64.   } 
  65.   else
  66.   {
  67.     do
  68.     {
  69.       switch (ships) 
  70.       {
  71.        case 'T': 
  72.     if (tf[player][tf_num].t < n_ships)
  73.       n_ships= tf[player][tf_num].t;
  74.     tf[player][tf_num].t=tf[player][tf_num].t-n_ships;
  75.     tf[player][new_tf].t=tf[player][new_tf].t+n_ships;
  76.     break;
  77.        case 'S': 
  78.     if (tf[player][tf_num].s < n_ships)
  79.       n_ships=tf[player][tf_num].s;
  80.     tf[player][tf_num].s=tf[player][tf_num].s-n_ships;
  81.     tf[player][new_tf].s=tf[player][new_tf].s+n_ships;
  82.     break;
  83.        case 'C': 
  84.     if (tf[player][tf_num].c < n_ships)
  85.       n_ships=tf[player][tf_num].c;
  86.     tf[player][tf_num].c=tf[player][tf_num].c-n_ships;
  87.     tf[player][new_tf].c=tf[player][new_tf].c+n_ships;
  88.     break;
  89.        case 'B': 
  90.     if (tf[player][tf_num].b < n_ships)
  91.       n_ships=tf[player][tf_num].b;
  92.     tf[player][tf_num].b=tf[player][tf_num].b-n_ships;
  93.     tf[player][new_tf].b=tf[player][new_tf].b+n_ships;
  94.     break;
  95.        default:
  96.     error("  ! Illegal field %c",ships);
  97.       } /*switch (*/
  98.       ships = get_token(iline,&n_ships);
  99.     } 
  100.     while (ships != ' ');
  101.   }
  102.  
  103.   x = tf[player][tf_num].x; 
  104.   y = tf[player][tf_num].y;
  105.  
  106.   zero_tf(player,tf_num);
  107.   zero_tf(player,new_tf);
  108.  
  109.   on_board(x,y);
  110.  
  111.   return(new_tf);
  112. }
  113.  
  114. void join_tf()
  115. {
  116.   char tf1,tf2; 
  117.   int tf1n,tf2n,value;
  118.   char iline[81];
  119.  
  120.   printf("oin tfs:");
  121.   get_line(iline);
  122.   clear_left();
  123.   tf1 = get_token(iline,&value);
  124.   tf1n=tf1-'A'+1;
  125.  
  126.   if ((tf1n<1) || (tf1n>26)) 
  127.   {
  128.     error("  ! illegal tf %c",tf1);
  129.     return;
  130.   }
  131.   if ((tf[player][tf1n].eta)>0) 
  132.   {
  133.     error("  !tf%c is not in normal space ", tf1);
  134.     return;
  135.   }
  136.   if (tf[player][tf1n].dest==0) 
  137.   {
  138.     error("  !nonexistent tf");
  139.     return;
  140.   }
  141.   if (tf[player][tf1n].blasting)
  142.   {
  143.     error("  !Tf is blasting a planet    ");
  144.     return;
  145.   }
  146.  
  147.   while ((tf2 = get_token(iline, &value)) != ' ')
  148.   {
  149.     tf2n = tf2-'A'+1;
  150.     if ((tf2n<1) || (tf2n>26)) 
  151.     {
  152.       error("  !illegal tf %c",tf2);
  153.       continue;
  154.     }
  155.     if (tf2n == tf1n) 
  156.     {
  157.       error("!Duplicate tf %c",tf2);
  158.       continue;
  159.     }
  160.     else if ((tf[player][tf2n].dest == 0)) 
  161.     {
  162.       error("!Nonexistant TF%c",tf2);
  163.       continue;
  164.     }
  165.     if ((tf[player][tf2n].x!=tf[player][tf1n].x) ||
  166.     (tf[player][tf2n].y!= tf[player][tf2n].y))
  167.     {
  168.       error("  !tf%c bad location", tf2);
  169.       continue;
  170.     }
  171.     else if (tf[player][tf2n].eta != 0)
  172.     {
  173.       error("  !tf%c is not in normal space ", tf2);
  174.       continue;
  175.     }
  176.     if (tf[player][tf2n].blasting) 
  177.     {
  178.       error(" !Tf%c is blasting a planet    ", tf2);
  179.       continue;
  180.     }
  181.     joinsilent(player,&tf[player][tf1n],&tf[player][tf2n]);
  182.   }
  183.   on_board(tf[player][tf1n].x,tf[player][tf1n].y);
  184.   point(1,19);
  185.   print_tf(tf1n);
  186. }
  187.  
  188. int get_tf(tteam tm, int starnum)
  189. {
  190.   int i;
  191.  
  192.   for (i=1; (i<=MAX_FLEETS) && (tf[tm][i].dest != 0); i++);
  193.   if (i==27) return(0);
  194.  
  195.   tf[tm][i].s = 0;
  196.   tf[tm][i].t = 0;
  197.   tf[tm][i].c = 0;
  198.   tf[tm][i].b = 0;
  199.   tf[tm][i].eta = 0;
  200.   tf[tm][i].x = stars[starnum].x;
  201.   tf[tm][i].y = stars[starnum].y;
  202.   tf[tm][i].xf = tf[tm][i].x;
  203.   tf[tm][i].yf = tf[tm][i].y;
  204.   tf[tm][i].dest = starnum;
  205.   tf[tm][i].origeta = 0;
  206.   tf[tm][i].blasting = false;
  207.   
  208.   return(i);
  209. }
  210.  
  211. void joinsilent(tteam team, struct sttf *parent, struct sttf *child)
  212. {
  213.   parent->t = parent->t + child->t;
  214.   parent->s = parent->s + child->s;
  215.   parent->c = parent->c + child->c;
  216.   parent->b = parent->b + child->b;
  217.  
  218.   if ((parent->dest!=0) && (child->dest!=0))
  219.     tf_stars[parent->dest][team]--;
  220.  
  221.   child->dest = 0;
  222. }
  223.